<?php
include 'test_header.php';

class test_db_obj_ranklist extends UnitTestCase{
	
	private $db ; 

	function setUp(){
		$this->db = db_connect();

		$sql = "
CREATE TABLE IF NOT EXISTS `ranklist` (
  `rank` int(11) NOT NULL,
  `username` varchar(255) NOT NULL,
  PRIMARY KEY (`username`),
  UNIQUE KEY `rank` (`rank`),
  UNIQUE KEY `username` (`username`),
  UNIQUE KEY `rank_2` (`rank`),
  KEY `rank_3` (`rank`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;			
		";

		$res = $this->db->query( $sql );

		$sql = "
INSERT INTO  `ranklist` (
`rank` ,
`username`
)
VALUES (
'1',  'root'
), (
'2',  'test'
)";

		$res = $this->db->query( $sql );

		$sql = "
CREATE TABLE IF NOT EXISTS `user_judge_statistics` (
  `username` varchar(256) NOT NULL,
  `submit_times` bigint(20) NOT NULL,
  `accepted_times` bigint(20) NOT NULL,
  `wrong_answer_times` bigint(20) NOT NULL,
  `presentation_times` bigint(20) NOT NULL,
  `compilation_error_times` bigint(20) NOT NULL,
  `time_exceeded_times` bigint(20) NOT NULL,
  `memory_exceeded_times` bigint(20) NOT NULL,
  `output_exceeded_times` bigint(20) NOT NULL,
  `runtime_error_times` bigint(20) NOT NULL,
  `compile_time_over` bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
	
		$res = $this->db->query( $sql );

$sql = "INSERT INTO `user_judge_statistics` (`username`, `submit_times`, `accepted_times`, `wrong_answer_times`, `presentation_times`, `compilation_error_times`, `time_exceeded_times`, `memory_exceeded_times`, `output_exceeded_times`, `runtime_error_times`, `compile_time_over`) VALUES
('test', 1000, 1, 2, 3, 4, 5, 6, 7, 8, 9),
('qweqweoiu', 111, 111, 1, 11, 111, 11111, 111, 111, 1, 111),
('adsad', 123, 12313, 123, 111, 3123, 123, 12313, 123131313, 1313, 1131),
('asdad', 123, 33, 12, 12333, 123, 12, 33, 23, 1211, 123),
('ewqwe ', 123, 1231, 12, 123132, 12313, 1313, 1111, 13245, 12345, 1313)";

	$res = $this->db->query( $sql );
	}

	function tearDown(){
		
		$sql = "drop table `ranklist`";

		$res = $this->db->query( $sql );
	
	}

	function test_get_ranklist(){
		
		$ranklist_proc = new ranklist_process( $this->db );
		$ranklist = $ranklist_proc->get_ranklist( $this->db );
		

		$this->assertTrue( $ranklist );
	}

	function test_update_ranklist(){
		
		$ranklist_proc = new ranklist_process( $this->db );
		$ranklist = $ranklist_proc->update_ranklist( $this->db );
		$this->assertTrue( $ranklist );

	}

}
	

$test = new test_db_obj_ranklist();
$test->run( new HtmlReporter() );

